package com.enlorenz.core.channel.socket.imp.longconnection.quick;

import com.enlorenz.core.base.IReqResMessageHandle;
import com.enlorenz.core.channel.socket.common.reader.DefaultNioReader;
import com.enlorenz.core.channel.socket.common.reader.DefaultSocketReader;
import com.enlorenz.core.channel.socket.common.translate.MessageSerializeTransformer;
import com.enlorenz.core.channel.socket.common.writer.DefaultNioWriter;
import com.enlorenz.core.channel.socket.common.writer.DefaultSocketWriter;
import com.enlorenz.core.channel.socket.imp.longconnection.LongRecvSendDoubleChannel;
import com.enlorenz.core.queue.transfer.imp.WaitMessageQueue;

/**
 * 快速创建收发长连接通道
 * @author lcb
 */
public class QuickLongRecvSendDoubleChannel {
	
	public static LongRecvSendDoubleChannel quickCreate(String clientIp,int clientPort,
			int serverPort,IReqResMessageHandle recvHandle,WaitMessageQueue clientQueue) throws Exception{
		LongRecvSendDoubleChannel recvSendChannel=new LongRecvSendDoubleChannel();
		recvSendChannel.setClientIp(clientIp);
		recvSendChannel.setClientPort(clientPort);
		recvSendChannel.setClientMessageBytesTransformer(new MessageSerializeTransformer());
		recvSendChannel.setClientQueue(clientQueue);
		recvSendChannel.setClientWriter(new DefaultSocketWriter());
		recvSendChannel.setSocketReader(new DefaultSocketReader());
		recvSendChannel.setServerPort(serverPort);
		recvSendChannel.setBacklog(50);
		recvSendChannel.setServerWriter(new DefaultNioWriter());
		recvSendChannel.setServerReader(new DefaultNioReader());
		recvSendChannel.setServerMessageBytesTransformer(new MessageSerializeTransformer());
		recvSendChannel.setRecvMsgHandle(recvHandle);
		recvSendChannel.setHandRecvThreadNum(10);
		return recvSendChannel;
	}
	
}
